package com.chen.blue.controller.admin.system;


import com.chen.blue.domain.delete.system.UserRoleDelete;
import com.chen.blue.domain.dto.system.UserRoleDto;
import com.chen.blue.domain.dto.system.update.UserRoleDtoEdit;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.DataResult;
import com.chen.blue.result.R;
import com.chen.blue.service.system.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户和角色关联表 前端控制器
 * </p>
 *
 * @author CLT
 * @since 2024-04-28
 */
//@Api(tags = "用户角色模块")
@Validated
@RestController
@RequestMapping("/user/role")
public class UserRoleController {

    @Resource
    private IUserRoleService iUserRoleService;

    //    @ApiOperation(value = "用户角色添加", notes = "用户角色添加")
    @PostMapping("/add")
    public R add(@RequestBody @Valid List<UserRoleDto> userRoleDtoList) throws DtoNullException {

        return iUserRoleService.addUserRole(userRoleDtoList) ? R.success() : R.faild();

    }

    //    @ApiOperation(value = "用户角色删除", notes = "用户角色删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody @Valid UserRoleDelete userRoleDelete) throws DtoNullException {
        return iUserRoleService.deleteUserRole(userRoleDelete) ? R.success() : R.faild();
    }

    //    @ApiOperation(value = "用户角色修改", notes = "用户角色修改")
    @PutMapping("/edit")
    public R updateById(@RequestBody @Valid List<UserRoleDtoEdit> userRoleDtoEditList) throws DtoNullException {

        return iUserRoleService.updateUserRole(userRoleDtoEditList) ? R.success() : R.faild();

    }

    //    @ApiOperation(value = "用户ID查询用户角色", notes = "用户ID查询用户角色")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Long userId) throws DtoNullException {

        return R.success(iUserRoleService.queryRoleById(userId));

    }


}

